package com.edu.dao.impl;

import com.edu.dao.BaseDao;
import com.edu.dao.BookDao;
import com.edu.entity.Book;
import com.edu.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl implements BookDao {
    @Override
    public List<Book> queray() {
        Connection con = null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        String sql = "SELECT * FROM Book";
        try {
            con= BaseDao.getConn();
            ps=con.prepareStatement(sql);
            rs= ps.executeQuery();
            List<Book> list=new ArrayList<Book>();
            while (rs.next()){
                Book book=new Book();
                book.setBookId(rs.getInt("bookId"));
                book.setBookName(rs.getString("bookName"));
                book.setBookType(rs.getString("bookType"));
                book.setBookWriter(rs.getString("bookWriter"));
                list.add(book);
            }
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(con,ps,rs);
        }
        return null;
    }
}
